Writes (or removes) JavaScript actions to an output file.
public static void WriteJavaScript(
string sourceFileName,
string password,
IList<PDFJavaScript> Script_,
string destinationFileName
)
public static void WriteJavaScript(
String^ sourceFileName,
String^ password,
IList<PDFJavaScript>^ Script_,
String^ destinationFileName
)
def WriteJavaScript(self,sourceFileName,password,Script_,destinationFileName):
sourceFileName
Name of the source PDF file.
password
The password to use if sourceFileName contains an encrypted PDF file.
javaScript
List of WriteJavaScript
actions to be written. If null or the array is empty, the function deletes the JavaScript from the file.
destinationFileName
Name of the destination PDF file.
If javaScript is not null and contains valid JavaScript actions, WriteJavaScript
will:
If the source PDF file contains JavaScript, those operations will be replaced by the actions from javaScript. To add JavaScript actions to the existing JavaScript actions from the source file, follow these steps:
WriteJavaScript
.If javaScript is null, WriteJavaScript
will remove any JavaScript from the file.
If destinationFileName is null or is equal to sourceFileName, the change will be performed in place and the source file will be modified.
There are several variations of this function, which take the source from a disk file or a stream and write the output to a disk file or a stream.
The actions from javaScript will be sorted in ascending order by the PDFJavaScript.Name property. This means the order in which the JavaScript actions are written to the file and executed by the JavaScript interpreter is not necessarily the order in which you add them to the javaScript list.
The example below demonstrates the result of this sort. The example adds two actions named name2
and name1
. The write however, changes the order and writes them in the order name1
, name2
. So when you load the resulting PDF file in a viewer that supports JavaScript (eg: web browser), the messages are displayed in reverse order.
using Leadtools.WinForms;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Controls;
using Leadtools.Drawing;
using Leadtools.ImageProcessing;
using Leadtools.Pdf;
using Leadtools.Svg;
public void TestWriteJavaScript_string_string_IList_string()
{
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, @"leadtools.pdf");
string dstFileName = Path.Combine(LEAD_VARS.ImagesDir, @"out.pdf");
List<PDFJavaScript> list = new List<PDFJavaScript>(2);
PDFJavaScript item;
item.Name = "name2";
item.Code = "app.alert(\"Hello 2\");";
list.Add(item);
item.Name = "name1";
item.Code = "app.alert(\"Hello 1\");";
list.Add(item);
PDFFile.WriteJavaScript(srcFileName, null, list, dstFileName);
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document